package com.starimmortal.excel.enumeration;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.stream.Stream;

/**
 * 性别枚举
 *
 * @author william@StarImmortal
 */
@Getter
@AllArgsConstructor
public enum GenderEnum {

	/**
	 * 未知
	 */
	UNKNOWN(0, "未知"),

	/**
	 * 男性
	 */
	MALE(1, "男性"),

	/**
	 * 女性
	 */
	FEMALE(2, "女性");

	private final Integer value;

	@JsonFormat
	private final String description;

	public static GenderEnum convert(Integer value) {
		return Stream.of(values()).filter(bean -> bean.value.equals(value)).findAny().orElse(UNKNOWN);
	}

	public static GenderEnum convert(String description) {
		return Stream.of(values()).filter(bean -> bean.description.equals(description)).findAny().orElse(UNKNOWN);
	}

}
